package com.wzh.himalaya.adapters;

import static android.media.AudioRecord.MetricsConstants.CHANNELS;

import android.content.Context;
import android.graphics.Color;
import android.telephony.TelephonyCallback;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.wzh.himalaya.MainActivity;
import com.wzh.himalaya.R;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.Arrays;
import java.util.List;

/**
 * className:IndicatorAdapter
 * Author:WZH
 * Time:2022-01-24
 */
public class IndicatorAdapter extends CommonNavigatorAdapter {

    private final String[] mTitle;
    private OnIndicatorTapClickListener mOnTabClickListener;

    //  private ViewPager mViewPager;

    public IndicatorAdapter(Context context) {
        mTitle=  context.getResources().getStringArray(R.array.indicator_title);
    }

    @Override
    public int getCount() {
        if(mTitle!=null)
        {
            return mTitle.length;
        }
        return 0;
    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {

        //创建View
        ColorTransitionPagerTitleView colorTransitionPagerTitleView = new ColorTransitionPagerTitleView(context);
        //设置一般情况下为灰色
        colorTransitionPagerTitleView.setNormalColor(Color.parseColor("#aaffffff"));
        colorTransitionPagerTitleView.setSelectedColor(Color.parseColor("#ffffff"));
        //单位sp
        colorTransitionPagerTitleView.setTextSize(18);
        //设置要显示的内容
        colorTransitionPagerTitleView.setText(mTitle[index]);
        //设置title的点击事件，这里的话，如果点击了title，就选中下面的viewpager到对应的index
        colorTransitionPagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //切换viewpager的内容，如果index不一样
                //todo:
                if(mOnTabClickListener!=null)
                {
                    mOnTabClickListener.onTabClick(index);
                }

            }
        });
        return colorTransitionPagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator  = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        indicator.setColors(Color.parseColor("#ffffff"));
        return  indicator;
    }

    public void setOnIndicatorTapClickListener(OnIndicatorTapClickListener listener){
        this.mOnTabClickListener = listener;
    }

    public interface OnIndicatorTapClickListener{
        void onTabClick(int index);
    }
}
